﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Job.Logic.BaseContent;
using System.Data;
using Job.Web.Framework;

namespace Job.Web.userControls.Hunter
{
    public partial class HunterJobList : BaseCtrl
    {
        HunterJobLogic logic = new HunterJobLogic();

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!this.IsPostBack)
            {
                BindCount();
                BindData();
            }
        }

        private void BindCount()
        {
            string key = this.tbSearchKey.Text.Trim();
            int count = logic.GetCount(key);
            if (count <= pagerTop.PageSize)
            {
                pagerTop.Visible = false;
                pagerButtom.Visible = false;
            }
            else
            {
                pagerButtom.RecordCount = count;
                pagerButtom.DataBind();
                pagerTop.RecordCount = count;
                pagerTop.DataBind();
            }
        }

        private void BindData()
        {
            int pageSize = pagerButtom.PageSize;
            int pageIdx = pagerButtom.CurrentPageIndex;

            string key = this.tbSearchKey.Text.Trim();
            DataTable dt = logic.GetJobPageList(pageSize, pageIdx, key);
            if ( null != dt )
            {
                this.jobList.DataSource = dt;
                this.jobList.DataBind();
            }
        }



        protected void pagerTop_PageChanged(object sender, EventArgs e)
        {
            BindData();
        }

        protected void pagerTop_PageChanging(object src, Wuqi.Webdiyer.PageChangingEventArgs e)
        {
            pagerButtom.CurrentPageIndex = e.NewPageIndex;
            Session["listcurrentPageIndex"] = e.NewPageIndex;
        }

        protected void pagerButtom_PageChanged(object sender, EventArgs e)
        {
            BindData();
        }

        protected void pagerButtom_PageChanging(object src, Wuqi.Webdiyer.PageChangingEventArgs e)
        {
            pagerTop.CurrentPageIndex = e.NewPageIndex;
            Session["listcurrentPageIndex"] = e.NewPageIndex;
        }

        protected void jobList_ItemDataBound(object sender, DataListItemEventArgs e)
        {
            ListItemType type = e.Item.ItemType;
            switch (type)
            {
                case ListItemType.Item:
                case ListItemType.AlternatingItem:
                    {
                        HyperLink jobDetail = (HyperLink)e.Item.FindControl("jobLink");
                        Label lbJobNo = (Label)e.Item.FindControl("jobNo");

                        jobDetail.NavigateUrl = WebCommon.GetApplicationPath(Request)  + "Item.aspx?categoryid="
                            + ((int)Constants.CategoryType.Hunter).ToString()
                            + "&subjectid=" + ((int)Constants.SubjectType.HunterPositionList).ToString()
                            + "&jobno=" + lbJobNo.Text.Trim();
                        break;
                    }
            }            

        }

        protected void btSearch_Click(object sender, EventArgs e)
        {
            BindCount();
            BindData();
        }

    }
}